/***
 * @company YIMAFU Co.
 * @copyright Copyright @2014, YIMAFU Co., Ltd. All right.
 * @since：JDK1.6
 * @version：1.0
 * @author chenlong
 * @see：
 ***/
package cn.com.qingz.core.listener;

import cn.com.qingz.modules.system.service.BasicService;
import org.apache.log4j.Logger;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author lifajun
 * @ClassName: ApplicationListener
 * @date 2013-6-25 下午1:06:58
 * @Description: 容器启动加载系统参数
 */
public class ApplicationInitListener implements ServletContextListener {

    private Logger log = Logger.getLogger(ApplicationInitListener.class);

    /**
     * 容器servletcontext
     */
    private ServletContext application;

    /**
     * 容器销毁
     */
    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        log.info("服务关闭......");
    }

    /**
     * 初始化时将ddinfo数据加载到application中
     *
     * @param
     * @auther : lifajun
     */
    @Override
    public void contextInitialized(ServletContextEvent context) {
        this.application = context.getServletContext();
        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
        BasicService basicService = wac.getBean(BasicService.class);
        basicService.doInitApplication(application);
    }
}
